#include <iostream>
#include <algorithm>

#define x first
#define y second

using namespace std;

const int N = 60;

typedef pair<int, int> PII;

int n, m;
int g[N][N];
PII q[N * N];
bool st[N][N];

int bfs(int sx, int sy) {
    int hh = 0, tt = 0;
    q[0] = {sx, sy};
    st[sx][sy] = true;
    
    int dx[4] = {0, -1, 0, 1}, dy[4] = {-1, 0, 1, 0};
    int area = 0;
    while (hh <= tt) {
        PII t = q[hh ++ ];
        area ++ ;
        
        for (int i = 0; i < 4; ++ i) {
            int a = t.x + dx[i], b = t.y + dy[i];
            if (g[t.x][t.y] >> i & 1) continue;
            if (a < 0 || a >= n || b < 0 || b >= m) continue;
            if (st[a][b]) continue;
            
            q[ ++ tt] = {a, b};
            st[a][b] = true;
        }
    }
    
    return area;
}

int main() {
    cin >> n >> m;
    
    for (int i = 0; i < n; ++ i)
        for (int j = 0; j < m; ++ j)
            cin >> g[i][j];
    
    
    int cnt = 0, area = 0;
    for (int i = 0; i < n; ++ i)
        for (int j = 0; j < m; ++ j)
            if (!st[i][j]) {
                area = max(area, bfs(i, j));
                cnt ++ ;
            }
            
    cout << cnt << endl;
    cout << area << endl;
    
    return 0;
}